#! /bin/bash

version=1.0.15
env=dev

cd .. || return
if [ ! -d seccomponent ]; then
  cd apm || return
  cd seccomponent || return
    rpm -ivh seccomponent-1.0.1-1.5.release.x86_64.rpm
    tar -zxvf SecComponent.tar.gz
    cp -a SecComponent /usr/local/
  cd .. || return
  cd .. || return
fi
cd apm || return

cp agent_$env.config apm-javaagent/apm.config

sh stop.sh

echo  "start product"
nohup  java -javaagent:apm-javaagent/apm-javaagent.jar=appName=product -jar apm2-demo-product.jar -Dserver.port=8082 -server -Xms300M -Xmx300M -Xss256k -XX:NewSize=300M -XX:MaxNewSize=300M -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Duser.timezone=Asia/Shanghai > product.log 2>&1 &

sleep 10

product=$(netstat -nlp | grep :8082 | awk '{print $7}' | awk -F"/" '{ print $1 }')

if [ -n "$product" ]; then
  echo  "start order"
  nohup  java -javaagent:apm-javaagent/apm-javaagent.jar=appName=order -jar apm2-demo-order.jar -Dserver.port=8081 -server -Xms300M -Xmx300M -Xss256k -XX:NewSize=300M -XX:MaxNewSize=300M -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Duser.timezone=Asia/Shanghai > order.log 2>&1 &
fi


echo  "start shopping"
nohup  java -javaagent:apm-javaagent/apm-javaagent.jar=appName=shopping-cart -jar apm2-demo-shopping.jar -Dserver.port=8083 -server -Xms300M -Xmx300M -Xss256k -XX:NewSize=300M -XX:MaxNewSize=300M -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Duser.timezone=Asia/Shanghai > shopping.log 2>&1 &

echo  "start web"
nohup  java -javaagent:apm-javaagent/apm-javaagent.jar=appName=web -jar apm2-demo-web.jar -Dserver.port=8084 -server -Xms300M -Xmx300M -Xss256k -XX:NewSize=300M -XX:MaxNewSize=300M -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Duser.timezone=Asia/Shanghai > web.log 2>&1 &

